﻿using Newtonsoft.Json.Linq;
using SDF.Plugin.Misc.SAPAdapter.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using SDF.Core;
using SDF.Core.Data;
using SDF.Plugin.Misc.SAPAdapter.Domain;
using SDF.Plugin.Misc.SAPAdapter.Core;
using SDF.Plugin.Misc.SAPAdapter.Services;
using SDF.Core.Infrastructure;

namespace SDF.Plugin.Misc.SAPAdapter.Controllers.Version1
{
    public class PingController : SAPWebApiBase
    {
        #region Fields
        ISAPConnectorService _sapService;
        #endregion

        #region Ctor
        PingController()
        {
            _sapService = EngineContext.Current.Resolve<ISAPConnectorService>();
        }
        #endregion

        #region Methods

        [HttpGet]
        public bool Get(string sapclient)
        {
            sapclient.NullOrEmptyCheck("sapclient");

            return _sapService.Ping(sapclient);
        }

        [HttpPost]
        public bool Post([FromBody]SapInstanceAPIModel model)
        {
            model.NullCheck("model");
            model.SAPInstance.NullOrEmptyCheck("SAPInstance");

            return _sapService.Ping(model.SAPInstance);
        }

        #endregion
    }
}